package com.witsight.platform.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.witsight.platform.dao.DynamicJpaRepository;
import com.witsight.platform.exception.BusinessException;
import com.witsight.platform.model.BoEntity;
import com.witsight.platform.service.BaseGenericService;

/**   
 * 说明：所有的Dao服务的基础类，所有的服务类都必须继承这个类
 * @Title: BaseGenericServiceImpl.java 
 * @Package com.witsight.platform.service.impl 
 * @See: {@link CommonServiceImpl}
 *       {@link BaseGenericService}
 * Copyright: Copyright (c) 2017
 * Company:sany huax witsight team by product
 * @author: penght  
 * @date: 2017年10月9日 上午8:28:18 
 * @version: V1.0
 *
 */
public abstract class BaseGenericServiceImpl<T, ID extends Serializable, M> extends CommonServiceImpl implements BaseGenericService<T, ID, M> {
	// 基础Dao Jpa
	private DynamicJpaRepository<T, ID, M> baseDao;
	/**
	 * 说明：构造函数
	 * 
	 * @Title:BaseGenericServiceImpl.java
	 * @See: 构造函数
	 * @param baseDao
	 *            注入基础Dao
	 * @date 2015年4月22日 下午8:29:09
	 */
	protected BaseGenericServiceImpl(DynamicJpaRepository<T, ID, M> baseDao) {
		super(baseDao);
		this.baseDao = baseDao;
	}
	/**
	 * 
	 * 说明：供继承者调用基本的dao
	 * 
	 * @Title: getbaseDao
	 * @See:供继承者调用基本的dao
	 * @author penght
	 * @return 基础Dao的接口
	 * @date: 2015年4月22日 下午8:34:32
	 */
	protected abstract DynamicJpaRepository<T, ID, M> getBaseDao();
	/**
	 * Returns whether an entity with the given id exists.
	 * 
	 * @param id must not be {@literal null}.
	 * @return true if an entity with the given id exists, {@literal false} otherwise
	 * @throws IllegalArgumentException if {@code id} is {@literal null}
	 */
	@Override
	public boolean exists(ID id) {
		return this.baseDao.exists(id);
	}
	
	@Override
	public T findOne(ID id) throws BusinessException {
		return this.baseDao.findOne(id);
	}

	@Override
	public List<T> findAll() throws BusinessException {
		return this.baseDao.findAll();
	}

	@Override
	public List<T> findAllByParams(String queryName, BoEntity params) {
		return this.baseDao.findAllByParams(queryName, params);
	}

	@Override
	public List<M> findBoEntitysByParams(String queryName, BoEntity params) {
		return this.baseDao.findBoEntitysByParams(queryName, params);
	}

	@Override
	public T findOneByParams(String queryName, BoEntity params) {
		return this.baseDao.findOneByParams(queryName, params);
	}

	@Override
	public M findBoEntityByParams(String queryName, BoEntity params) {
		return this.baseDao.findBoEntityByParams(queryName, params);
	}

	@Override
	public Page<T> findPageByParams(String queryName, BoEntity params, Pageable pageable) {
		return this.baseDao.findPageByParams(queryName, params, pageable);
	}

	@Override
	public Page<M> findPageBoEntityByParams(String queryName, BoEntity params, Pageable pageable) {
		return this.baseDao.findPageBoEntityByParams(queryName, params, pageable);
	}
}
